<?php
header ('Content-type: text/html; charset=utf-8');

if (!defined('IN_ADMIN')) {
    exit('Access Denied');
}

$mpurl  = 'admin.php?ac=femaleAuth';
$length = !empty($_POST['length']) ? intval($_POST['length']) : 20;
$list   = array();
$status = isset($_GET['status'])? $_GET['status'] : 1;
$page   = !empty($_GET['page'])? $_GET['page'] : 1;
$style  = array(
		'status' =>array(0 =>'',1 => '',2 => ''),
		'length'  =>array(20 => '',50 => '',100 => ''),
        );
if($_GET['op']=='permit'){//允许OR不允许
    $param=array(
        'do'    => 'femaleAuth',
        'action'=> 'permitFemaleAuth',
        'format'=>'json',
        'uuid'  => $_POST['uuid'],
        'status'=> $_POST['permit'],
        
    );
      
    $info=json_decode(get_api_content($_SC ['apiurl'], $param),TRUE);
      
    echo json_encode($info['resultData']);
    exit;
   
}elseif($_GET['op']=='reapply'){
    $param=array(
        'do'    => 'femaleAuth',
        'action'=> 'reapplyFemaleAuth',
        'format'=>'json',
        'uuid'  => $_POST['uuid'],
    );
    $info=json_decode(get_api_content($_SC ['apiurl'], $param),TRUE);
    
    echo json_encode($info['resultData']);
    exit;
    
}else{  
    $statusInfo = array(0=>'女生认证成功',1=>'女生认证申请中',2=>'女生认证失败');
	//分页	
	$params=array(
			'do'     =>'femaleAuth',
			'action' => 'getFemaleAuthListNumberByStatus',
			'status'=> $status,
			'format'=>'json'
	);
	$result=json_decode(get_api_content($_SC['apiurl'],$params),TRUE);//默认为申请记录数
	
	//总记录数
	$totalNumber = intval($result['resultData']);
	//$totalNumber = 1;
	if(intval($totalNumber) != 0){		
		//总页数
		$pages = ceil(intval($totalNumber)/$length);
		
		$pageurl = pagepation($page, $pages, $mpurl,$status);
		
		$nextpurl   = $pageurl ['next'];
		$prevpurl   = $pageurl ['prev'];
		$mpurl      = $pageurl ['urls'];
		$firstpurl  = $pageurl ['first'];
		$lastpurl   = $pageurl ['last'];
		
		$pageHtml = "<ul class='pagination'>
		<li class='text'><a href={$firstpurl}>首页</a></li>
		<li class='text'><a href={$prevpurl}>上一页</a></li>
		<li class='text'><a href=$mpurl>第 {$page} 页/共 {$pages} 页</a></li>
		<li class='text'><a href={$nextpurl}>下一页</a></li>
		<li class='text'><a href={$lastpurl}>末页</a></li>
		</ul>";
		
	    $param=array(
	        'do'     =>'femaleAuth',
	        'action' => 'getFemaleAuthList',
	        'status' => $status,
	        'uuid'   => 0,
	        'start'  => 0,
	        'length' => $length,
	        'format'=>'json'
	    );
	      
	    if(isset($_GET['submited']) || isset($_GET['pagepation'])){
	    	
	    	if(intval($_GET['uuid']) < 1){      
	    		$status = intval($_GET['status']);
		        $page   = intval($_GET['page']);
		        if(intval($page) < 1) $page = 1; 
		        $start=($page - 1)*$length;
		        $param=array(
		            'do'     =>'femaleAuth',
		            'action' => 'getFemaleAuthList',
		            'status'=> $status,
		            'uuid'  => $_GET['uuid'],
		            'start'  => $start,
		            'length' => $length,
		            'format'=>'json'
		        );           
	    	}else{
	    		$param=array(
	    				'do'     =>'femaleAuth',
	    				'action' => 'getUserFemaleAuthInfo',
	    				'uuid'  => intval($_GET['uuid']),
	    				'format'=>'json'
	    		);
	    	}
	    	$style['status'][$status] = $style['length'][$length] = 'selected';
	    }    
	
	
	    $info = get_api_content($_SC['apiurl'], $param);
	    $info=json_decode($info,TRUE);
	   
	    $list = $info['resultData'];  
	 
	}
}
//分页
function pagepation($page, $totalPages, $mpurl,$status){
	$firsturl = $mpurl. '&pagepation=1&status='.$status.'&page=1';
	$nexturl = '';
	if ($page < $totalPages)
	{
		$nexturl = $mpurl . '&pagepation=1&status='.$status.'&page=' . ($page+1);
	}
	$cureent = $mpurl . '&pagepation=1&status='.$status.'&page=' . $page;
	$preurl = '';
	if ($page>1) {
		$preurl = $mpurl . '&pagepation=1&status='.$status.'&page=' . ($page - 1);
	}
	$lasturl = $mpurl . '&pagepation=1&status='.$status.'&page=' . $totalPages;
	
	$result =  array (
			'first' => $firsturl,
			'next' 	=> $nexturl,
			'prev' 	=> $preurl,
			'last'	=> $lasturl,
			'urls' 	=> $cureent
	);
	return $result;
}
//将对应状态码转换为中文含义
function interpretationState($status){
    $s=array(0,1,2,4);
    if(in_array($status, $s)){
        switch ($status) {
            case 0:
                echo '认证成功';
                break;
            case 1:
                echo '认证中';
                break;
            case 2:
                echo '拉黑';
                break;
            case 4:
            	echo '申请失败';
                break;
        }
    }else{
        echo '未知';
    }
}

include_once template("admin/femaleAuth");
exit;
